package com.wwc.common.context;

import com.wwc.common.response.MemberLoginResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 创建本地线程，获取会员id
 */
public class LoginMemberContext{
	private static final Logger LOG = LoggerFactory.getLogger(LoginMemberContext.class);

	private static final ThreadLocal<MemberLoginResponse> member = new ThreadLocal<>();

	public static MemberLoginResponse getMember(){
		return member.get();
	}

	public static void setMember(MemberLoginResponse member){
		LoginMemberContext.member.set(member);
	}

	public static Long getId(){
		try{
			return member.get().getId();
		}catch(Exception e){
			LOG.error("获取登录会员信息异常", e);
			throw e;
		}
	}
}
